//==============================================================================
/**
 * @file	cb_tool.c
 * @brief	カスタムボールアプリ内サブルーチン群
 * @author	iwasawa
 * @date	2008.04.14
 */
//==============================================================================
#include "common.h"
#include "poketool/poke_tool.h"
#include "system/procsys.h"
#include "system/snd_tool.h"
#include "include/system/lib_pack.h"
#include "include/system/brightness.h"
#include "include/system/heapdefine.h"
#include "include/system/touch_subwindow.h"
#include "include/gflib/strbuf.h"
#include "include/gflib/msg_print.h"

#include "include/system/fontproc.h"
#include "include/system/msgdata.h"
#include "include/system/arc_util.h"
#include "include/system/window.h"
#include "include/poketool/pokeicon.h"

#include "field/field_common.h"
#include "field/field_event.h"
#include "field/fieldsys.h"
#include "field/ev_mapchange.h"

#include "system/bmp_menu.h"
#include "system/palanm.h"
#include "system/clact_tool.h"
#include "system/wipe.h"
#include "system/pm_overlay.h"

#include "battle/battle_common.h"
#include "battle/graphic/batt_bg_gs_def.h"
#include "pokeanime/p_anm_sys.h"
#include "savedata/record.h"

#include "data/cb_data_def.h"
#include "cb_snd_def.h"
#include "cb_sys.h"

/**
 *	@brief	デフォルトブレンド設定
 */
void CB_Tool_DefaultBlendSet(void)
{
#if 0
	G2_SetBlendAlpha(GX_BLEND_PLANEMASK_NONE,
					 GX_BLEND_PLANEMASK_BG1 | GX_BLEND_PLANEMASK_BG2, 11, 7);
	G2S_SetBlendAlpha(GX_BLEND_PLANEMASK_NONE,
					  GX_BLEND_PLANEMASK_BG1 | GX_BLEND_PLANEMASK_BG2 |
					  GX_BLEND_PLANEMASK_BG3, 7, 8);
#else
	G2_SetBlendAlpha(GX_BLEND_PLANEMASK_NONE,GX_BLEND_PLANEMASK_NONE, 31, 31);
	G2S_SetBlendAlpha(GX_BLEND_PLANEMASK_NONE,GX_BLEND_PLANEMASK_NONE,31, 31);
#endif
}

///< 動かないボタンの当たり判定
///< 横並び
static const RECT_HIT_TBL hit_tbl[] = {
	{ 16, 16 + 16,   8,   8 + 16	},	///< seal
	{ 16, 16 + 16,  64,  64 + 16	},	///< seal
	{ 40, 40 + 16,   8,   8 + 16	},
	{ 40, 40 + 16,  64,  64 + 16	},
	{ 64, 64 + 16,   8,   8 + 16	},
	{ 64, 64 + 16,  64,  64 + 16	},
	{ 88, 88 + 16,   8,   8 + 16	},
	{ 88, 88 + 16,  64,  64 + 16	},

	{104,104 + 24,  8,   8 + 40	},	///< ↑
	{104,104 + 24, 56,  56 + 40	},	///< ↓
	{168,188,  18,  77	},			///< L
	{168,188,  97,  156	},			///< C
	{168,188, 178,  237	},			///< R
};

/// アタリ判定初期化
void CB_Tool_ButtonInit(CB_MAIN_WORK* cbmw)
{
	int i;
	const RECT_HIT_TBL hit_tbl_dmy = { 0, 0, 0, 0 };

	for (i = 0; i < CB_ENUM_BTN_NUM; i++){
		cbmw->sys.hit_tbl[i] = hit_tbl[i];
	}
	for ( ; i < CB_BHIT_SEAL_MAX; i++){
		cbmw->sys.hit_tbl[i] = hit_tbl_dmy;
		cbmw->seal[i - CB_BHIT_SEAL_0].hit = &cbmw->sys.hit_tbl[i];
	}

	cbmw->sys.btn = BMN_Create(cbmw->sys.hit_tbl, CB_DEF_HIT_TBL_MAX,
							   CB_ButtonCallBack, cbmw, HEAPID_CUSTOM_BALL);
}

void CB_Tool_CoreDataRemove(CB_MAIN_WORK* cbmw, int this)
{
	int poke_idx;
	int poke_this;
	int none_data = 0;
	CB_CORE temp;

	///< ポケパラ操作
	poke_this = cbmw->cb_edit_data[ this ].poke_idx;
	if (poke_this != CB_DEF_POKE_NOT_INDEX){
		PokeParaPut(cbmw->cb_pw->poke_para[ poke_this ], ID_PARA_cb_id, (u8*)&none_data);
	}
	cbmw->cb_edit_data[ this ].poke_idx = CB_DEF_POKE_NOT_INDEX;

	SubSelect_ObjRefrect(cbmw);
}
